import time

from Test.unit_03.Page import Page
from selenium.webdriver.common.by import By

class Page2(Page):
    # 1输入框：国台
    # 输入框定位
    search_loc = (By.TAG_NAME, 'input')
    def search(self):
        self.send_keys(self.search_loc,'国台')
    # 2对输入框进行回车事件
    def send_key_enter(self):
        self.keys_Enter(self.search_loc)
    # 断言：国台旗舰店 /html/body/div[6]/div/div[2]/div[2]/div[2]/a
    dy1_loc = (By.XPATH, '/html/body/div[6]/div/div[2]/div[2]/div[2]/a')
    def dy1(self):
        self.get_text(self.dy1_loc)
    # 3点击店铺
    # 定位元素
    goshop_loc = (By.XPATH, '/html/body/div[6]/div/div[2]/div[2]/a')
    def goshop(self):
        self.click(self.goshop_loc)
    # 6点击加入购物车
    # 定位加入购物车元素
    cart_loc = (By.XPATH, '//area[@href="http://www.jiuxian.com/goods-28877.html"]')
    def add_cart(self):
        self.click(self.cart_loc)
    dy2_loc = (By.XPATH, '/html/body/div[5]/div[2]/span')
    def dy2(self):
        self.get_text(self.dy2_loc)
    # 8点击到货通知
    # addToCartForDetail
    addToCartForDetail_loc = (By.ID, 'addToCartForDetail')
    def addTo(self):
        self.click(self.addToCartForDetail_loc)
    # 9输入通知邮箱号
    notify_form_loc = (By.CLASS_NAME, 'notify-form')
    def notify_clear(self):
        self.clear(self.notify_form_loc)
    def notify_sned(self):
        self.send_keys(self.notify_form_loc,'2829138788@qq.com')
    # 10点击确定
    notify_sure_loc = (By.ID, 'notify-sure')
    def notify_sure(self):
        self.click(self.notify_sure_loc)
    # dy:bind-send-text 我们会在到货后第一时间给您通知，谢谢关注！
    bind_send_text_loc = (By.CLASS_NAME, 'bind-send-text')
    def dy3(self):
        a = self.get_text(self.bind_send_text_loc)
        print(a)
    # 11点击确定
    notify_popSuc_sure_loc = (By.ID, 'notify-popSuc-sure')
    def notify_popSuc(self):
        self.click(self.notify_popSuc_sure_loc)
    # 业务逻辑
    def jiuxian2_luoji(self):
        self.jiuxian_luoji()
        # 1输入框：国台
        self.search()
        # 2对输入框进行回车事件
        self.send_key_enter()
        # 3点击店铺
        self.goshop()
        # 4窗口切换
        self.new_window()
        time.sleep(3)
        # 5向下滚动1500像素
        self.scr_down(2000)
        time.sleep(3)
        # 6点击加入购物车
        self.add_cart()
        # 7窗口切换
        self.new_window()
        # 8点击到货通知
        self.addTo()
        # 9输入通知邮箱号
        self.notify_clear()
        self.notify_sned()
        # 10点击确定
        self.notify_sure()
        self.gettext()
        # 11点击确定
        self.notify_popSuc()